#!/bin/sh
export g_arch="x86_64"
# host是要在哪个架构机器上运行.
# export g_host=""


# 当前脚本的架构目录
g_scriptArchDir=${g_scriptPlatformDir}/${g_arch}
# 当前Build的架构目录
g_buildArchDir=${g_buildPlatformDir}/${g_arch}
if [[ ! -e "${g_buildArchDir}" ]]; then 
	mkdir -p ${g_buildArchDir}
fi

g_outputArchDir=${g_outputPlatformDir}/${g_arch}
if [[ ! -e "${g_outputArchDir}" ]]; then 
	mkdir -p ${g_outputArchDir}
fi


main () {
    echo "+++ Build for ${g_platform} with ${g_arch} Start +++"

    libsString=`jq -r ".libs|keys[]" $g_configFile`
    #删除\r字符
    libsString2=`echo $libsString | tr -d "\r"`
    # 第一个元素名字后面加上了\r???
    # 使用\n分割字符串
    libs=($libsString2)
    
    for lib in ${libs[@]}; do
        echo "processing ${lib}..."
        query=".libs.${lib}.version"
        # echo "jq -r $query $g_configFile"
        action=`eval "jq -r '.libs.${lib}.action' $g_configFile"`
        echo "action: $action"
        [[ "$action" == "$COMPILE_ACTION_IGNORE" ]] && continue
        libVersion=`eval "jq -r '.libs.${lib}.version' $g_configFile"`
        echo "${lib} version is: $libVersion"
        export g_libId="${lib}_${libVersion}"
        # 定义各个类具体实现
        . ${g_scriptArchDir}/${g_libId}.sh
        build $action
    done
    # export g_libId="zlib_1.3.1"
    # . ${g_scriptArchDir}/${g_platform}-${g_arch}-${g_libId}.sh Y Y
	#openssl
    # export g_libId="lame-3.100"
	# . ${g_scriptArchDir}/${g_platform}_${g_arch}_${g_libId}.sh N N
	# export PKG_CONFIG_PATH+=":${g_outputArchDir}/${g_libId}/lib/pkgconfig" 

    # export g_libId="Mp3TranscodeDemo"
    # gcc
    # . ${g_scriptArchDir}/${g_platform}_${g_arch}_${g_libId}.sh

    # make
    # . ${g_scriptArchDir}/${g_platform}_${g_arch}_${g_libId}_make.sh Y Y

    # cmake
    # . ${g_scriptArchDir}/${g_platform}_${g_arch}_${g_libId}_cmake.sh Y Y

    echo "=== Build for ${g_platform} with ${g_arch} End ===\n\n\n"
}

main
